﻿using Entity.Front_Desk;
using Entity.ResultModel;
using Entity.ResultModel.Menu;
using Hotel.Models;
using IHotelBLL.IEmployeeBLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace Hotel.Controllers.Menu
{
    public class Menu : Controller
    {
        ResultModel result = new ResultModel();
        IMenuBLL _munuBLL;
        public Menu(IMenuBLL menuBLL)
        {
            _munuBLL = menuBLL;
        }
        public IActionResult GetMenu()
        {
            MenuDefault menuDefault;
            string userId = HttpContext.Session.GetString("employeeId");
            if (userId is null)
            {
                menuDefault = new MenuDefault(null);
            }
            else
            {
                List<MenuModel> menus = _munuBLL.GetMenuInfos(userId);
                menuDefault = new MenuDefault(menus);
            }
            return Json(menuDefault);
        }
        public IActionResult GetMenus(int page,int limit)
        {
            var res = new
            {
                code = 0,
                data = _munuBLL.GetMenuInfos(page, limit, out int count),
                count
            };
            return Json(res);
        }
        public IActionResult GetMenuOptions(string menuId)
        {
            result.Data = _munuBLL.GetMenuOptions(menuId);
            result.Status = 1;
            result.IsSuccess = true;
            return Json(result);
        }
        public IActionResult AddMenu(MenuInfo menuInfo)
        {
            if(menuInfo.Title == null)
            {
                result.Msg = "标题不能为空";
                return Json(result);
            }
            result.IsSuccess = _munuBLL.AddMenu(menuInfo,out string msg);
            result.Msg = msg;
            return Json(result);
        }
        public IActionResult GetMenuInfoById(string id)
        {
            result.Data = _munuBLL.GetMenuInfoById(id);
            return Json(result);
        }
        public IActionResult DeleteMenu(string MenuId)
        {
            if (MenuId == null)
            {
                result.Msg = "用户Id不能为空";
                return Json(result);
            }
            result.IsSuccess = _munuBLL.DeleteMenu(MenuId,out string msg);
            result.Msg =msg;
            return Json(result);
        }
        public IActionResult UpdateMenu(string id, string description, string title, string href, string parentId, int level, string icon,int sort, string target)
        {
            result.IsSuccess = _munuBLL.EditMenu(id,description,title,href,parentId,level,icon,target,sort ,out string msg);
            result.Msg=msg;
            return Json(result);
        }
    }
}
